﻿using System;

namespace UnityMethods.Extend
{
    public static partial class Ext
    {
        #region 是否为空

        /// <summary>
        /// 是否为空
        /// </summary>
        /// <param name="value">值</param>
        public static bool IsEmpty(this string value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        /// <summary>
        /// 是否为空
        /// </summary>
        /// <param name="value">值</param>
        public static bool IsEmpty(this Guid? value)
        {
            if (value == null)
            {
                return true;
            }

            return IsEmpty(value.Value);
        }

        /// <summary>
        /// 是否为空
        /// </summary>
        /// <param name="value">值</param>
        public static bool IsEmpty(this Guid value)
        {
            if (value == Guid.Empty)
            {
                return true;
            }

            return false;
        }

        /// <summary>
        /// 是否为空
        /// </summary>
        /// <param name="value">值</param>
        public static bool IsEmpty(this object value)
        {
            if (value != null && !string.IsNullOrEmpty(value.ToString()))
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        #endregion

        #region 判断字符串是否是数字

        /// <summary>
        /// 判断是否是数字
        /// </summary>
        /// <param name="message"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public static bool IsNumberic(this string message)
        {
            System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
            if (rex.IsMatch(message))
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 从字符串中提取数字
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static string GetNumbericFromStr(this string message)
        {
            return System.Text.RegularExpressions.Regex.Replace(message, @"[^0-9]+", "");
        }

        #endregion
      
        public static bool StrEquals(this string data, string data2)
        {
            if (data.IsEmpty() || data2.IsEmpty())
            {
                return false;
            }

            return data.Equals(data2);
        }

    }
}
